Socket
Socket
Sign inDemoInstall

jsonpath

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonpath

Query JavaScript objects with JSONPath expressions. Robust / safe JSONPath engine for Node.js.


Version published
Maintainers
1
Created

What is jsonpath?

The jsonpath npm package allows users to query and manipulate JSON documents using a query language for JSON. It provides capabilities to extract specific data from a JSON structure, similar to XPath for XML.

What are jsonpath's main functionalities?

Query JSON

This feature allows you to query JSON for specific values using a JSONPath expression. In the code sample, it extracts the prices of books from a JSON object.

const jsonpath = require('jsonpath');
const json = { store: { book: [{ price: 10 }, { price: 20 }] } };
const prices = jsonpath.query(json, '$.store.book[*].price');
console.log(prices); // [10, 20]

Apply a callback to query results

This feature allows you to apply a callback function to each item in the result of a JSONPath query. In the code sample, it doubles the prices of books.

const jsonpath = require('jsonpath');
const json = { store: { book: [{ price: 10 }, { price: 20 }] } };
jsonpath.apply(json, '$.store.book[*].price', value => value * 2);
console.log(json); // { store: { book: [{ price: 20 }, { price: 40 }] } }

Find paths to query results

This feature retrieves the paths of query results within a JSON document. In the code sample, it finds the paths to the prices of books.

const jsonpath = require('jsonpath');
const json = { store: { book: [{ price: 10 }, { price: 20 }] } };
const paths = jsonpath.paths(json, '$.store.book[*].price');
console.log(paths); // [['$', 'store', 'book', 0, 'price'], ['$', 'store', 'book', 1, 'price']]

Parse JSONPath expressions

This feature parses a JSONPath expression and returns its structure. This can be useful for understanding or debugging complex JSONPath queries.

const jsonpath = require('jsonpath');
const expression = jsonpath.parse('$.store.book[*].price');
console.log(expression); // Outputs the parsed structure of the JSONPath expression

Other packages similar to jsonpath

Keywords

FAQs

Package last updated on 01 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc